package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateDeviceWhiteListDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateDeviceWhiteListSaveDTO;
import com.itlong.cloud.POJO.VO.operate.DeviceWhiteListDetailVO;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceWhiteListVO;
import com.itlong.cloud.POJO.VO.operate.OperateMacInfoVO;
import com.itlong.cloud.equip.operate.IOperateDeviceWhiteListServiceClient;
import com.itlong.cloud.operate.service.IOperateDeviceWhiteListService;
import com.itlong.cloud.utils.page.Page;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <desc>
 *      运营-设备白名单管理接口暴露实现类
 * </desc>
 *
 * @createDate2019/12/11
 **/
@RestController
public class OperateDeviceWhiteListServiceResource implements IOperateDeviceWhiteListServiceClient {

    @Autowired
    IOperateDeviceWhiteListService iOperateDeviceWhiteListService;

    /**
     * <desc>
     *      分页查询设备白名单信息
     * </desc>
     *
     * @param operateDeviceWhiteListDTO 查询参数DTO
     * @return  设备白名单分页数据
     * @Author Zhu.yj
     * @createDate  2019/12/11
     */
    @Override
    @RequestMapping(path = "/operate/device/whiteList/getWhiteListByPage",method = RequestMethod.POST)
    public Page<OperateDeviceWhiteListVO> getWhiteListByPage(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.getWhiteListByPage(operateDeviceWhiteListDTO);
    }

    /**
     * <desc>
     *      保存设备白名单信息
     * </desc>
     *
     * @param operateDeviceWhiteListDTO 参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/12
     */
    @Override
    @RequestMapping(path = "/operate/device/whiteList/save",method = RequestMethod.POST)
    public Integer save(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.save(operateDeviceWhiteListDTO);
    }

    /**
     * <desc>
     *      禁用或删除设备白名单
     * </desc>
     *
     * @param operateDeviceWhiteListDTO 参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/12
     */
    @Override
    @RequestMapping(path = "/operate/device/whiteList/forbidden",method = RequestMethod.POST)
    public Integer forbidden(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.forbidden(operateDeviceWhiteListDTO);
    }

    /**
     * <desc>
     *      根据mac地址获取设备白名单信息
     * </desc>
     *
     * @param mac mac地址
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/16
     */
    @Override
    @RequestMapping(path = "/operate/device/whiteList/getWhiteListByMac",method = RequestMethod.POST)
    public OperateDeviceWhiteListVO getWhiteListByMac(@RequestParam("mac") String mac) throws Exception {
        return iOperateDeviceWhiteListService.getWhiteListByMac(mac);
    }

    /**
     * <desc>
     *      获取设备白名单信息状态
     * </desc>
     *
     * @param deviceUnique 设备编号
     * @return
     * @Author Zhu.yj
     * @createDate  2019/12/23
     */
    @Override
    @RequestMapping(path = "/operate/device/whiteList/getWhiteListStatus",method = RequestMethod.POST)
    public Integer getWhiteListStatus(@RequestParam("deviceUnique") String deviceUnique) throws Exception{
        return iOperateDeviceWhiteListService.getWhiteListStatus(deviceUnique);
    }

    /**
     * <desc>
     *      获取设备白名单详情
     * </desc>
     *
     * @param whiteListId 白名单id
     * @return
     * @Author Zhu.yj
     * @createDate  2020/8/11
     */
    @PostMapping("/operate/device/white/getDetail")
    @Override
    public DeviceWhiteListDetailVO getDetail(@RequestParam("whiteListId") String whiteListId) throws Exception {
        return iOperateDeviceWhiteListService.getDetail(whiteListId);
    }

    /**
     * <desc>
     *      获取所有mac地址
     * </desc>
     *
     * @param
     * @return
     * @Author Zhu.yj
     * @createDate  2020/8/11
     */
    @PostMapping("/operate/device/white/getMacList")
    @Override
    public List<OperateMacInfoVO> getMacList() throws Exception {
        return iOperateDeviceWhiteListService.getMacList();
    }

    /**
     * <desc>
     *      批量导入设备白名单列表
     * </desc>
     *
     * @param whiteListSaveDTOList 设备白名单列表
     * @return
     * @Author Zhu.yj
     * @createDate  2020/8/11
     */
    @PostMapping("/operate/device/whiteList/importDeviceWhiteList")
    @Override
    public Integer importDeviceWhiteList(@RequestBody List<OperateDeviceWhiteListSaveDTO> whiteListSaveDTOList) throws Exception {
        return iOperateDeviceWhiteListService.importDeviceWhiteList(whiteListSaveDTOList);
    }

    /**
     * <desc>
     * 根据上传的mac地址和授权文件id更新白名单中的设备激活状态
     * </desc>
     *
     * @param operateDeviceWhiteListDTO
     * @Author chengshican
     * @Date 2020-08-16 10:14
     * @Param operateDeviceWhiteListDTO 参数
     * @Return
     * @Exception
     */

    @PostMapping("/operate/device/whiteList/updateStatusByAuthIdAndMAC")
    @Override
    public int updateStatusByAuthIdAndMAC(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.updateStatusByAuthIdAndMAC(operateDeviceWhiteListDTO);
    }

    /**
     * <desc>
     * 根据上传的mac地址更新白名单中的设备异常标记和是否转换为设备白名单
     * </desc>
     *
     * @param operateDeviceWhiteListDTO
     * @Author chengshican
     * @Date 2020-08-16 10:14
     * @Param operateDeviceWhiteListDTO 参数
     * @Return
     * @Exception
     */
    @Override
    public int updateFlagByMAC(OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return  iOperateDeviceWhiteListService.updateFlagByMAC(operateDeviceWhiteListDTO);
    }

    /**
     * <desc>
     *      添加备注
     * </desc>
     *
     * @param operateDeviceWhiteListDTO 设备白名单DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/9/2
     */
    @Override
    @PostMapping("/operate/device/whiteList/update")
    public Integer update(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.update(operateDeviceWhiteListDTO);
    }
    /**
     * <desc>
     *      转换为白名单
     * </desc>
     *
     * @param operateDeviceWhiteListDTO 设备白名单DTO
     * @return 受影响行数
     * @Author Zhu.yj
     * @createDate  2020/9/2
     */
    @Override
    @PostMapping("/operate/device/whiteList/convertToWhiteList")
    public Integer convertToWhiteList(@RequestBody OperateDeviceWhiteListDTO operateDeviceWhiteListDTO) throws Exception {
        return iOperateDeviceWhiteListService.convertToWhiteList(operateDeviceWhiteListDTO);
    }
}
